package com.example.viewdemo

import android.annotation.SuppressLint
import android.graphics.Color
import android.graphics.Typeface
import android.os.Bundle
import android.text.TextUtils
import android.util.Log
import android.widget.Button
import android.widget.TextView
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

class TestTextView : AppCompatActivity() {
    @SuppressLint("SetTextI18n")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_test_text_view)
        val extraData = intent.getStringExtra("extra_data")
        Log.d("SecondActivity", "extra data is $extraData")

        val testTv1: TextView = findViewById(R.id.textView3)
        val testTv2: TextView = findViewById(R.id.textView4)
        val testBtn: Button = findViewById(R.id.retrunBtn)

        testBtn.setOnClickListener {
            finish()

        }
        // 记录原始文本和样式
        val originalText1 = testTv1.text
        val originalText2 = testTv2.text

        testTv1.setOnClickListener {
            // 切换文本
            if (testTv1.text == originalText1) {
                testTv1.text = "文字修改"
            } else {
                testTv1.text = originalText1
            }
        }

        testTv2.setOnClickListener {

            if (testTv2.text == originalText2) {
                testTv2.text = "text change"
                testTv2.setTextColor(Color.BLACK) //
                testTv2.setBackgroundColor(Color.RED) //
                testTv2.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD))
                testTv2.letterSpacing = 0.1F
            } else {
            }

        }

        val textView5 = findViewById<TextView>(R.id.textView5)
        textView5.text = "这是一段非常长的文本，需要跑马灯效果来显示。"

        textView5.ellipsize = TextUtils.TruncateAt.MARQUEE
        textView5.isSingleLine = true
        textView5.isFocusable = true
        textView5.isFocusableInTouchMode = true
        textView5.marqueeRepeatLimit = -1 // marquee_forever

        // 确保 TextView 可以获取焦点
        textView5.requestFocus()


        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
    }
}

